package com.itlong.cloud.sdk.resource;

import com.itlong.cloud.POJO.PO.ProjectPO;
import com.itlong.cloud.POJO.PO.PropertyRoleProjectPO;
import com.itlong.cloud.project.sdk.ISDKServerOldProjectServiceClient;
import com.itlong.cloud.sdk.service.ISDKServerOldProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      SDK服务暴露接口实现类.
 * </desc>
 *
 * @createDate 2017/10/31
 */
@RestController
public class SDKServerOldProjectServiceResource implements ISDKServerOldProjectServiceClient {

    @Autowired
    ISDKServerOldProjectService iSDKProjectService;

    /**
     * <desc>
     *      根据自定义参数查询项目
     * <desc/>
     * @param  params   查询参数集
     * @return  List<ProjectPO>  返回PO对象集
     * @author Biao.R
     * @createDate 2017/10/31
     */
    @PostMapping(path = "sdkServer/project/getByParamMap")
    @Override
    public List<ProjectPO> getByParamMap(@RequestBody Map<String, Object> params) {
        return iSDKProjectService.getByParamMap(params);
    }

    /**
     * <desc>
     *      查找以beginStr开头的最大项目编号
     * <desc/>
     * @param   beginStr 查询的起始字符串
     * @return  String  返回的项目编号
     * @author Biao.R
     * @createDate 2017/10/31
     */
    @Override
    @PostMapping(path = "sdkServer/project/getMaxId")
    public Integer getMaxId(@RequestParam("beginStr") String beginStr) {
        return iSDKProjectService.getMaxId(beginStr);
    }


    /**
     * <desc>
     *      根据项目名称保存projectPO信息
     * <desc/>
     * @param   appid 当前登录userId
     * @param   projectName 保存对象
     * @return  Integer  返回的保存数量
     * @author Biao.R
     * @createDate 2017/10/31
     */
    @PostMapping(path = "sdkServer/project/saveByProjectName")
    @Override
    public ProjectPO saveByProjectName(@RequestParam("appid") String appid, @RequestParam("projectName") String projectName) throws Exception {
        return iSDKProjectService.saveByProjectName(appid,projectName);
    }

    /**
     * <desc>
     *      查询独立开发者所管辖的项目信息
     * <desc/>
     * @param   propertyRoleProjectPO 独立开发者PO对象
     * @return  List<ProjectPO> 查询出的项目信息结果集
     * @author Biao.R
     * @createDate 2017/11/3
     */
    @Override
    @PostMapping(path = "sdkServer/project/getDeveloperProjects")
    public List<ProjectPO> getDeveloperProjects(@RequestBody PropertyRoleProjectPO propertyRoleProjectPO) {
        return iSDKProjectService.getDeveloperProjects(propertyRoleProjectPO);
    }

    /**
     * <desc>
     *      根据项目ID查询单个项目
     * <desc/>
     * @param  projectId  待查询项目ID
     * @return  ProjectPO  返回对象
     * @author Biao.R
     * @createDate 2017/11/9
     */
    @PostMapping(path = "sdkServer/project/getByProjectId")
    @Override
    public ProjectPO getByProjectId(@RequestParam("projectId") String projectId) {
        return iSDKProjectService.getByProjectId(projectId);
    }

}